<?php

global $group;
$group = [];

function route_init($req_body, $rsp_body)
{
    //https://www.php.net/manual/en/function.call-user-func.php

    $name = $req_body["name"] ?? '';
    $tmp = explode(".", $name);


    $controller = "\\app\\$name";
    $method = "index";


    $prefix = "";
    if (count($tmp) == 2) {
        $prefix = $tmp[0];
        $name1 = $tmp[1];
    }

    foreach ($GLOBALS['group'] as $item) {
        if ($item['prefix'] == $prefix) {
            $resp = call_user_func([$controller, $method], $req_body, $rsp_body);
            print_r($resp);
        }
    }

    return $rsp_body;
}